package IOUtil;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public abstract class FileUtil {

	public abstract String getCaminho();
	public abstract String getConteudo();

	public boolean isContinuous() {
		return false;
	}
	public BufferedReader importarFile() throws ImportacaoException {
		File f = new File(getCaminho());
		BufferedReader bufferedReader = null;
		try {
			FileReader reader = new FileReader(f);

			bufferedReader = new BufferedReader(reader);
		} catch (FileNotFoundException e) {
			throw new ImportacaoException("Arquivo n�o encontrado");
		}
		return bufferedReader;
	}

	public void salvarFile() throws ExportacaoException {
		File f = new File(getCaminho());

		BufferedWriter bw = null;

		try {
			FileWriter w = new FileWriter(f,isContinuous());

			bw = new BufferedWriter(w);

			bw.write(getConteudo());

		} catch (IOException e) {
			throw new ExportacaoException("Nao foi possivel exportar o arquivo");
		} finally {
			if (bw != null) {
				try {
					bw.close();
				} catch (IOException e) {
					throw new ExportacaoException(
							"Nao foi possivel fechar o arquivo de exportacao");
				}
			}
		}
	}
/*
	public void salvarFile(Boolean s) throws ExportacaoException {
		File f = new File(getCaminho());

		BufferedWriter bw = null;

		try {
			FileWriter w = new FileWriter(f, s);

			bw = new BufferedWriter(w);

			bw.write(getConteudo());

		} catch (IOException e) {
			throw new ExportacaoException("Nao foi possivel exportar o arquivo");
		} finally {
			if (bw != null) {
				try {
					bw.close();
				} catch (IOException e) {
					throw new ExportacaoException(
							"Nao foi possivel fechar o arquivo de exportacao");
				}
			}
		}
	}*/
}
